def right_side_view(root):
    if root is None:
        return []
    res = []
    nodes = [root]
    while len(nodes) != 0:
        res.append(nodes[0].val)
        tmp = []
        for node in nodes:
            if node.right is not None:
                tmp.append(node.right)
            if node.left is not None:
                tmp.append(node.left)
        nodes = tmp
    return res
